//
//  PlaceService.m
//  YouthOlympic2014
//
//  Created by Li Yuhang on 14-7-1.
//  Copyright (c) 2014年 mitian. All rights reserved.
//

#import "PlaceService.h"

@implementation PlaceService



-(void) getAllPlaces:(CompletionBlock)completion
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSError* error = nil;
        NSArray* result = nil;
        id jsonObj =  [self.api GetLocation: [AppUtils getLan]];
        NSString* errorMsg = [[jsonObj objectForKey:@"ApiErrorInfo"] objectForKey:@"msg"];
        
        if (errorMsg != nil) {
            error = [NSError errorWithDomain:errorMsg code:400 userInfo:nil];
        }else{
            result =[Place instanceList:jsonObj];
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            completion(result,error);
        });
    });
}

-(void) getAllSubPlaces: (NSString *) placeId
             completion:(CompletionBlock)completion
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSError* error = nil;
        NSArray* result = nil;
        id jsonObj =  [self.api GetSubLocation:placeId withLan:[AppUtils getLan]];
        NSString* errorMsg = [[jsonObj objectForKey:@"ApiErrorInfo"] objectForKey:@"msg"];
        
        if (errorMsg != nil) {
            error = [NSError errorWithDomain:errorMsg code:400 userInfo:nil];
        }else{
            result =[SubPlace instanceList:jsonObj];
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            completion(result,error);
        });
    });
};

/*
-(NSArray*) getAllPlaces{
    id jsonObj =  [self.api GetLocation: [AppUtils getLan]];
    
    return [Place instanceList:jsonObj];
}

-(NSArray*) getAllSubPlaces: (NSString *) placeId{
    id jsonObj =  [self.api GetSubLocation:placeId withLan:[AppUtils getLan]];
    
    return [SubPlace instanceList:jsonObj];
}
*/
@end
